home *** CD-ROM | disk | FTP | other *** search
/ MacFormat UK 55 / MF_UK_55_1.iso / mac / Shareware Plus / Developers / VideoToolbox / (Utilities) / GrabDrivers / GrabSlotDrivers.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-27  |  4.7 KB  |  150 lines  |  [TEXT/CWIE]

  1. /* GrabSlotDrivers.c
  2. Repeatedly calls the Slot Manager to get every slot driver and puts each in its
  3. own file. These files can then be perused with the ResEdit CODE viewer. 
  4.  
  5. The ResEdit CODE viewer is a public domain file, for use with ResEdit, distributed by:
  6. Ira L. Ruben
  7. Apple Computer, Inc.
  8. 20525 Mariani Ave., MS: 37-A
  9. Cupertino, Ca. 95014
  10. Ira@Apple.Com
  11. ftp://ftp.apple.com/dts/mac/tools/resedit/
  12.  
  13. Note that GrabSlotDrivers gets the driver directly from the card's configuration
  14. ROM, whereas it is possible that your run-time System is actually superceding
  15. that by a later version of the driver loaded from the System file or by an INIT.
  16. If you want the active version of the driver it would be best to get it from the
  17. device manager, which is what GrabVideoDrivers.c does, though it skips non-video
  18. devices.
  19.  
  20. HISTORY:
  21. 2/89 dgp Wrote it as "video hacker II" using THINK C 3.
  22. 1/3/93 dgp updated it to THINK C 5 and renamed it GrabSlotDrivers.c
  23. 5/11/93    dgp    added check for Slot Manager, in response to bug report by Jonathan Brecher.
  24. 7/29/94 dgp Eliminated use of "#s" printf format, since it's not supported by
  25.             Metrowerks CodeWarrior C.
  26. 9/5/94 dgp removed assumption in printf's that int==short.
  27. 6/8/95 dgp Made sure that Mac structs are always 68k aligned.
  28. */
  29. #include "VideoToolbox.h"
  30. //#include <Errors.h>
  31. //#include <Resources.h>
  32. #ifndef __TRAPS__
  33.     #include <Traps.h>
  34. #endif
  35. #include <ROMDefs.h>
  36. //#include <Video.h>
  37.  
  38. #if PRAGMA_ALIGN_SUPPORTED || __MWERKS__
  39.     #pragma options align=mac68k
  40. #endif
  41.  
  42. typedef struct {
  43.     short flags;
  44.     short blanks[3];
  45.     short open;
  46.     short prime;
  47.     short control;
  48.     short status;
  49.     short close;
  50.     Str255 name;
  51. } VideoDriver;
  52.  
  53. #if PRAGMA_ALIGN_SUPPORTED || __MWERKS__
  54.     #pragma options align=reset
  55. #endif
  56.  
  57. void AddResourceToFile(unsigned char *filename,unsigned char *name,ResType type,int id
  58.     ,Handle handle);
  59. void GrabSlotDrivers(void);
  60.  
  61. void main(void)
  62. {
  63.     Require(0);
  64.     if(!TrapAvailable(_SlotManager))
  65.         PrintfExit("Sorry, no Slot Manager.\n");
  66.     MaximizeConsoleHeight();
  67.     printf(BreakLines("Welcome to GrabSlotDrivers.\n"
  68.     "This programs copies all drivers from your slot devices. "
  69.     "Note that this gets the driver from the card's configuration ROM, whereas "
  70.     "it is possible that at run-time your System replaces "
  71.     "that by a later version of the driver loaded from the System file or INIT.\n\n",78));
  72.     GrabSlotDrivers();
  73. }
  74.  
  75. void GrabSlotDrivers(void)
  76. {
  77.     SpBlock spBlock;
  78.     SEBlock sEBlock;
  79.     unsigned char name[256],filename[32];
  80.     int error,version;
  81.     Ptr *handle;
  82.     VideoDriver *videoDriverPtr;
  83.     unsigned char *bytePtr;
  84.     Boolean newSlotMgr;    // SGetTypeSRsrc requires system 7 slot manager
  85.  
  86.     newSlotMgr=(SVersion(&spBlock)==noErr);
  87.     spBlock.spsExecPBlk = (Ptr) &sEBlock;
  88.     spBlock.spSlot = 0;
  89.     spBlock.spID = 0;
  90.     spBlock.spExtDev = 0;
  91. /*
  92.     spBlock.spCategory=catDisplay;
  93.     spBlock.spCType=0;
  94.     spBlock.spDrvrSW=0;
  95.     spBlock.spDrvrHW=0;
  96.     spBlock.spTBMask=3;    // ignore DrvrHW and DrvrSW
  97. */
  98.     while(1){
  99.         spBlock.spParamData=5;    // next resource, whether enabled & disabled
  100.         if(newSlotMgr)error=SGetSRsrc(&spBlock);
  101.         else error=SNextSRsrc(&spBlock);
  102.         if(error==smNoMoresRsrcs) break;
  103.         if(error){
  104.             printf("SNextSRsrc/SGetSRsrc error %d\n",error);
  105.             break;
  106.         }
  107.         spBlock.spResult = (unsigned long) &name;
  108.         error = SReadDrvrName(&spBlock);
  109.         p2cstr(name);
  110.         printf("SReadDrvrName=%s\n",name);
  111.         c2pstr((char *)name);
  112.         printf("spSlot=%d,spID=%u,spExtDev=%d"
  113.             ,(int)spBlock.spSlot,(unsigned int)spBlock.spID,(int)spBlock.spExtDev);
  114.         printf(",spCategory=%d,spCType=%d,spDrvrSW=%d,spDrvrHW=%d,spRefNum=%d\n"
  115.             ,(int)spBlock.spCategory,(int)spBlock.spCType,(int)spBlock.spDrvrSW
  116.             ,(int)spBlock.spDrvrHW,(int)spBlock.spRefNum);
  117.         memcpy(filename,name,32);
  118.         /* filename must be truncated to 31 characters */
  119.         if(filename[0] > 31) filename[0]=31;
  120.         // Replace leading "." by "-" since the Mac filing system 
  121.         // is confused by filenames beginning with ".".
  122.         if(filename[1]=='.')filename[1]='-';
  123.         
  124.         /* get handle to desired driver resource */
  125.         error = SGetDriver(&spBlock);
  126.         if(!error) {
  127.             handle = (Ptr *) spBlock.spResult;
  128.     
  129.             // Is this a video driver?
  130.             videoDriverPtr=*(VideoDriver **)handle;
  131.             if(EqualString(name,videoDriverPtr->name,1,1)){
  132.                 // Probably is a video driver. The version number of a video driver 
  133.                 // is the first word-aligned word after the name string.
  134.                 bytePtr= videoDriverPtr->name;
  135.                 bytePtr += 1+bytePtr[0];    /* go to end of Pascal string */
  136.                 bytePtr = (unsigned char *)((long)(bytePtr+1) & ~1);    // round up to word boundary
  137.                 version = *(short *)bytePtr;
  138.             } else version=rand();
  139.         
  140.             AddResourceToFile(filename,name,'DRVR',version,handle);
  141.             printf("Driver copied to file “%s”, with resource id %d\n"
  142.                 ,p2cstr(filename),(int)version);
  143.             DisposHandle(handle);
  144.         }
  145.         else printf("No driver.\n");
  146.         printf("\n");
  147.     }
  148. }
  149.  
  150.